package co.yixiang.huiMin.controller;


import co.yixiang.annotation.AnonymousAccess;
import co.yixiang.huiMin.entity.CarTypes;
import co.yixiang.huiMin.entity.DriveTypes;
import co.yixiang.huiMin.service.CarTypesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 车辆类型 前端控制器
 * </p>
 *
 * @author Author
 * @since 2020-08-04
 */
@RestController
@Api(tags = "车辆分类")
@RequestMapping("/carTypes")
public class CarTypesController {

    @Resource
    private CarTypesService carTypesService;

    /**
     * 查询车辆分类
     * @return
     */
    @AnonymousAccess
    @ApiOperation("查询车辆分类")
    @GetMapping("/selectCarTypes")
    public ResponseEntity<Object> selectCarTypes() {
        List<CarTypes> list=carTypesService.selectCarTypes();

        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("code",200);
        resultMap.put("message", list);
        return new ResponseEntity<>(resultMap, HttpStatus.OK);

    }



    /**
     *添加车辆分类
     * @return
     */
    @AnonymousAccess
    @ApiOperation("添加车辆分类")
    @PostMapping("/insertCarTypes")
    public ResponseEntity<Object> insertCarTypes(@RequestBody CarTypes carTypes){
        int count=carTypesService.insertCarTypes(carTypes);
        HashMap<String, Object> resultMap = new HashMap<>();
        if(count>0){
            resultMap.put("code",200);
            return new ResponseEntity<>(resultMap, HttpStatus.OK);
        }
        resultMap.put("code",300);
        return new ResponseEntity<>(resultMap, HttpStatus.OK);
    }


    /**
     * 根据id查询车辆分类详情
     * @return
     */
    @AnonymousAccess
    @ApiOperation("根据id查询车辆分类详情")
    @GetMapping("/selectDriveTypesById")
    public ResponseEntity<Object> selectDriveTypesById(String id) {
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("code",200);
        resultMap.put("message", carTypesService.selectCarTypesById(id));
        return new ResponseEntity<>(resultMap, HttpStatus.OK);

    }

    /**
     *修改车辆分类
     * @return
     */
    @AnonymousAccess
    @ApiOperation("修改车辆分类")
    @PostMapping("/updateCarTypes")
    public ResponseEntity<Object> updateCarTypes(@RequestBody CarTypes carTypes){

        int count=carTypesService.updateCarTypes(carTypes);
        HashMap<String, Object> resultMap = new HashMap<>();
        if(count>0){
            resultMap.put("code",200);
            return new ResponseEntity<>(resultMap, HttpStatus.OK);
        }
        resultMap.put("code",300);
        return new ResponseEntity<>(resultMap, HttpStatus.OK);
    }

    /**
     *删除车辆分类
     * @return
     */
    @AnonymousAccess
    @ApiOperation("删除车辆分类")
    @PostMapping("/deleteCarTypes")
    public ResponseEntity<Object> deleteCarTypes(@RequestBody CarTypes carTypes){
        carTypes.setDelFlag(1);
        int count=carTypesService.updateCarTypes(carTypes);
        HashMap<String, Object> resultMap = new HashMap<>();
        if(count>0){
            resultMap.put("code",200);
            return new ResponseEntity<>(resultMap, HttpStatus.OK);
        }
        resultMap.put("code",300);
        return new ResponseEntity<>(resultMap, HttpStatus.OK);
    }
}

